/*
 * @Author: songliusheng
 * @Date: 2018-11-12 10:20:33
 * @Description: ''
 * @Last Modified by: zoushiyong
 * @Last Modified time: 2018-11-23 18:17:48
 * @ToDo: ''
 */

import React from 'react'
import { Button, Table } from 'antd'
import { actions } from 'mirrorx'
import PromoButton from './PromoButton'

let statusArr = [
  { name: 'All', status: 1 },
  { name: 'Ready', status: 2 },
  { name: 'In Progress', status: 3 },
  { name: 'End', status: 4 }
]
let CouponList = (props) => {
  const columns = [
    { title: 'Name', key: 'name', dataIndex: 'name', width: 300 },
    { title: 'Type',
      key: 'type',
      width: 140,
      dataIndex: 'type',
      render: (value, record) => {
        return <span>
          {value === 1 ? '1 code 1 person' : 'Gerneral Code'}
        </span>
      } },
    { title: 'Value(SGD)',
      key: 'value',
      dataIndex: 'value',
      render: (value, record) => {
        return <div>
          <div>{value}</div>
          <span className='sub-text'>( minimum consumpition: {record.minConsumption})</span>
        </div>
      } },
    { title: 'Recive Limit',
      width: 120,
      key: 'maxReceiveTimes',
      dataIndex: 'maxReceiveTimes',
      render: (value, record) => {
        return <div>
          <div>{value}</div>
          <span className='sub-text'>
            (store:{record.availableStore})</span>
        </div>
      } },
    { title: 'Effective Period',
      key: '',
      dataIndex: 'effective',
      render: (value, record) => {
        let { effectiveStartDate: start, effectiveEndDate: end } = record
        start = start.substr(0, 10).replace(/-/g, '.')
        end = end.substr(0, 10).replace(/-/g, '.')

        return <div>{start} - {end}</div>
      } },
    { title: 'Operation',
      key: 'operation',
      width: 210,
      dataIndex: 'operation',
      render: (value, record) => {
        return <div className='operation'>
          <Button
            onClick={() => actions.routing.push({
              pathname: '/page-coupon-detail',
              search: `?id=${record.id}&name=${record.name}` })}
            className='operate-btn'>Detail</Button>

          {/* 显示下载QRcode的悬浮框 */}
          {
            props.menuAuth
              ? <span>
                {
                  record.status !== 4
                    ? <PromoButton
                      url={`yfyb-fusion-za-fusion-mobile-mall.test.za-tech.net/coupon?promoBatchId=${record.id}&pid=${props.partnerId}`} />
                    : <Button
                      className='ml10'
                      disabled>Invalid</Button>
                }
              </span>
              : <Button className='disabled-operate-btn' disabled>Promotion</Button>
          }

        </div>
      } }
  ]
  return <Table
    pagination={{
      showQuickJumper: true,
      total: props.rowTotal
    }}
    rowKey='asd'
    onChange={props.pageChange}
    dataSource={props.rows}
    columns={columns} />
}

export default CouponList
